package xdu.lz.protocol.socekt;

import xdu.lz.framework.RequestWrap;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * @date 2020/5/15 23:01
 */
public class SocketClient {


    public String refer(String hostName, Integer port, RequestWrap requestWrap){
        try {
            Socket socket = new Socket(hostName,port);
            ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream()) ;
            System.out.println("【socekt client export】: write requestWrap "+requestWrap);
            output.writeObject(requestWrap);
            ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
            String result = (String) input.readObject();
            System.out.println("【socekt client get result from server】 "+result);
            output.close();
            input.close();
            socket.close();
            return result;
        }catch (Exception e){
            e.printStackTrace();
        }


        return null;
    }
}
